package com.icode.web.controller.house;

import com.icode.core.dto.house.ForEnumDTO;
import com.icode.core.dto.house.HouseBaseDTO;
import com.icode.core.model.house.HouseBaseArea;
import com.icode.service.house.HouseService;
import com.icode.service.house.HouseWeeklyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: xianfei
 * Date: 15-9-9
 * Time: 下午7:54
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/house_week_time")
public class HouseWeekTimeController {

    @Autowired
    private HouseWeeklyService houseWeeklyService;


    @RequestMapping(value = "show", method = RequestMethod.GET)
    private String show(Model model) {
        List<ForEnumDTO> areas = HouseBaseArea.toDTOs();
        model.addAttribute("areas", areas);
        return "back/houseBase/houseWeekTimeOverView";
    }

    @RequestMapping(value = "update", method = RequestMethod.GET)
    private String update(Model model) {
        List<ForEnumDTO> areas = HouseBaseArea.toDTOs();
        model.addAttribute("areas", areas);
        return "back/houseBase/houseWeekTime";
    }

    @RequestMapping(value = "divide_time", method = RequestMethod.POST)
    private String divideTime(String houseWeekGuid, String time) {
        houseWeeklyService.divideWeekTime(houseWeekGuid, time);
        return "redirect:/house_week_time/update";
    }

    @RequestMapping(value = "find_house_info/{area}", method = RequestMethod.GET)
    public void findHouseInfoByArea(@PathVariable String area, HttpServletResponse response) {
        houseWeeklyService.findHouseInfoForHouseWeekTime(area, response);
    }

    @RequestMapping(value = "find_week_type/{area}/{houseInfoGuid}", method = RequestMethod.GET)
    private void findHouseWeekType(@PathVariable String area, @PathVariable String houseInfoGuid, HttpServletResponse response) {
        houseWeeklyService.findHouseWeekType(area, houseInfoGuid, response);
    }

    @RequestMapping(value = "find_house_week/{area}", method = RequestMethod.GET)
    private void findHouseWeek(@PathVariable String area, HttpServletResponse response) {
        houseWeeklyService.findHouseWeekTimeByArea(area, response);
    }

    @RequestMapping(value = "del/{guids}", method = RequestMethod.GET)
    private String houseWeekTimeDel(@PathVariable String guids) {
        houseWeeklyService.deleteHouseWeekTimeByGuids(guids);
        return "redirect:/house_week_time/show";
    }
}
